﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Graphics_Factory
{
    public class graphicsFactory
    {
        public static IShape createGraphics(String str)
        {
            IShape shape = null;
            
            try
            {
                if (str == "c")
                {
                    shape = new Circle();
                }
                else if (str == "r")
                {
                    shape = new Rectangle();
                }
                else if (str == "t")
                {
                    shape = new Triangle();
                }
                else
                {
                    throw new UnSupportedShapeException("不能生成这种形状");
                }
            }
            catch (UnSupportedShapeException ex)
            {

                Console.WriteLine(ex);
            }
            return shape;
        }
    }
    
    public class UnSupportedShapeException : Exception
    {
        public UnSupportedShapeException() { }
        public UnSupportedShapeException(String str,Exception exception) : base(str, exception) { }
        public UnSupportedShapeException(String str) : base(str) { }
       
    }



}
